package com.alibaba.otter.manager.web.service;

import com.alibaba.otter.manager.biz.config.datamediasource.DataMediaSourceService;
import com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource;
import org.springframework.stereotype.Service;

@Service
public class DataMediaSourceAggService {


    private final DataMediaSourceService dataMediaSourceService;

    public DataMediaSourceAggService(DataMediaSourceService dataMediaSourceService) {
        this.dataMediaSourceService = dataMediaSourceService;
    }


    public void create(DbMediaSource dbDataMedia) {


        if (dbDataMedia.getType().isMysql()) {
            dbDataMedia.setDriver("com.mysql.cj.jdbc.Driver");
        } else if (dbDataMedia.getType().isOracle()) {
            dbDataMedia.setDriver("oracle.jdbc.driver.OracleDriver");
        }
        dataMediaSourceService.create(dbDataMedia);

    }


    public void modify(DbMediaSource dbDataMedia) {


        if (dbDataMedia.getType().isMysql()) {
            dbDataMedia.setDriver("com.mysql.cj.jdbc.Driver");
        } else if (dbDataMedia.getType().isOracle()) {
            dbDataMedia.setDriver("oracle.jdbc.driver.OracleDriver");
        }
        dataMediaSourceService.modify(dbDataMedia);

    }
}
